<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
	<script>
		$(function(){
			goodsList()
		})
		function goodsList(){
            $.ajax({
                url: "/goods/goodsList",
                data: {goodsName:$("#goodsName").val(),pageNum: $("#pageNum").val(),pageSize: $("#pageSize").val()},
                type: "post",
                dataType: "json",
                async: false,
                success: function (result) {
                    if (result.code == 10000){
                        var list = result.data.rows;
                        var list1 = result.rows;
                        var str ='';
                        for (var i = 0;i < list.length; i++){
                            str+='<tr>'
                            str+='<td><input type="checkbox" name="box" value="'+list[i].id+'"></td>'
                            str+='<td>'+list[i].id+'</td>'
                            str+='<td>'+list[i].goodsName+'</td>'
                            str+='<td>'+list[i].price+'</td>'


                            for (var j =0;j<list1.length;j++){
                                if (list1[j].id == list[i].category1Id){
                                    str+='<td>'+list1[j].name+'</td>'
                                }
                            }

                            for (var x =0;x<list1.length;x++){
                                if (list1[x].id == list[i].category2Id){
                                    str+='<td>'+list1[x].name+'</td>'
                                }
                            }

                            for (var w =0;w<list1.length;w++){
                                if (list1[w].id == list[i].category3Id){
                                    str+='<td>'+list1[w].name+'</td>'
                                }
                            }
                            str+='<td>'
                            if (list[i].auditStatus == 0){
                                str +='<span>未审核</span>'
                            }else if (list[i].auditStatus == 1){
                                str +='<span>审核通过</span>'
                            }else if (list[i].auditStatus == 2){
                                str +='<span>审核不通过</span>'
                            }
                            str+='</td>'
                            str+='</tr>'
                        }
                    }
                    $("#goodsList").html(str);
                    pageinstall(result.data);
                },error:function (e) {
                    console.log(e);
                }
            })
		}

        function pageinstall(page){
            $("#pageNum").val(page.pageNum);
            $("#pageSize").val(page.pageSize);
            $("#total").val(page.total);
            $("#pages").val(page.pages);
        }

        function toPage(flag){
            var pageNum = parseInt($("#pageNum").val());
            var pages = parseInt($("#pages").val());
            if(flag == 1){
                if(pageNum <= 1){
                    alert("已经是首页");
                    return;
                }
                $("#pageNum").val(pageNum - 1);
            }else if(flag == 2){
                if(pageNum >= pages){
                    alert("已经是尾页");
                    return;
                }
                $("#pageNum").val(pageNum + 1);
            }else if(flag == 3){
                if(pageNum <= 1){
                    alert("已经是首页");
                    return;
                }
                $("#pageNum").val(1);
            }else if(flag == 4){
                if(pageNum >= pages){
                    alert("已经是尾页");
                    return;
                }
                $("#pageNum").val(pages);
            }
            goodsList();
        }

        //审核
        function shenhe(auditStatus){
		    var ids =[];
		    var box = document.getElementsByName("box");
		    for (var i = 0;i<box.length;i++){
                if (box[i].checked){
                    ids.push(box[i].value)
                }
            }
		    $.ajax({
                url:"/goods/isShenhe",
                data:{ids:ids,auditStatus:auditStatus},
                dataType:"json",
                type:"post",
                async:false,
                success:function(result){
                    if (result.code == 10000){
                    alert("审核成功")
                        goodsList();
                    }

                },error:function(){
                    alert("错了.....")
                }
            })
        }
        //删除
        function deleteById(){
            var ids =[];
            var box = document.getElementsByName("box");
            for (var i = 0;i<box.length;i++){
                if (box[i].checked){
                    ids.push(box[i].value)
                }
            }
            $.ajax({
                url:"/goods/deleteById",
                data:{ids:ids},
                dataType:"json",
                type:"post",
                async:false,
                success:function(result){
                    if (result.code == 10000){
                        alert("删除成功")
                        goodsList();
                    }

                },error:function(){
                    alert("错了.....")
                }
            })
        }
	</script>
</head>
<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品审核</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" onclick="deleteById()" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" onclick="shenhe(1)" title="审核通过" ><i class="fa fa-check"></i> 审核通过</button>
                                        <button type="button" class="btn btn-default" onclick="shenhe(2)" title="驳回" ><i class="fa fa-ban"></i> 驳回</button>
                                        <button type="button" class="btn btn-default" title="刷新" ><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
                                    商品名称：<input type="text" id="goodsName" name="goodsName">
									<button class="btn btn-default" onclick="goodsList()">查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
			                              <th class="" style="padding-right:0px">
			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">
			                              </th> 
										  <th class="sorting_asc">商品ID</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">二级分类</th>
									      <th class="sorting">三级分类</th>
									      <th class="sorting">状态</th>
			                          </tr>
			                      </thead>
			                      <tbody id="goodsList">

			                      </tbody>
			                  </table>
			                  <!--数据列表/-->                        
							  
							 
                        </div>
                        <!-- 数据表格 /-->
                        
                        
                     </div>
                    <!-- /.box-body -->
  <a href="javascript:toPage(3)">首页</a>
  <a href="javascript:toPage(1)">上一页</a>
  <a href="javascript:toPage(2)">下一页</a>
  <a href="javascript:toPage(4)">尾页</a>
  第<input type="text" id="pageNum" name="pageNum" size="2px" >页
  共<input type="text" id="total"  name="total" size="2px" readonly="readonly">条
  总<input type="text" id="pages"  name="pages" size="2px" readonly="readonly">页
  每页<input type="text" id="pageSize"  name="pageSize" size="2px" readonly="readonly">条
</body>

</html>